{% extends 'base.html' %}
{% block self_head_css_js %}
    <script src="/static/layer/layer.js"></script>
{% endblock %}
{% block content %}
<script>
    window.onload=init;
    function init() {
        showhide(2);
    }
    function showhide(n) {
        var box = document.getElementById("setup");
        box.className="active";
        var box2 = document.getElementById("joblist");
        box2.className="active";
    }
</script>


<div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
    </section>

    <!-- Main content -->
    <section class="content">
    {% include 'setup/setup_navbar.html' %}

        <form action="{% url 'job_result_del' %}" method="post">
                    {% csrf_token %}
            <div class="box box-info">
                <div class="box-header">
                </div>
                <!-- /.box-header -->
                <div class="box-body">
                  <table class="table table-striped table-bordered" id="dataform">
                      <thead>
                        <tr>
                            <th>
                                <input type="checkbox" onclick="checkAll(this, 'item1');" />
                            </th>
                                    <th>任务类型</th>
                                    <th>任务状态</th>
                                    <th>任务指令</th>
                                    <th>完成时间</th>
                                    <th>任务结果</th>
                                    <th>任务异常</th>
                                </tr>
                            </thead>
                            <tbody>
                                {% if result_info %}
                                {% for res in result_info %}
                                    <tr class="even gradeA">
                                        <td><input type="checkbox" id="u_id" class="item1" value="{{ res.id }}" name="idc_check" /></td>
                                        <td><a href="#"><li style="list-style-type:none" onclick="return tanchu(this.value)" value="{{ res.id }}"> {{ res.task_name }}</li></a></td>
                                        <td>{{ res.status }}</td>
                                        <td><div style="overflow-y:scroll;width: 200px;height: 100px;">{{ res.task_kwargs }}</div></td>
                                        <td>{{ res.date_done|date:"Y-m-d H:i:s" }}</td>
                                        {% if  res.result %}
                                            <td><div style="overflow-y:scroll;width: 200px;height: 100px;">{{ res.result }}</div></td>
                                        {% else %}
                                            <td>{{ res.result }}</td>
                                        {% endif %}
                                        {% if  res.traceback %}
                                            <td><div style="overflow-y:scroll;width: 200px;height: 100px;">{{ res.traceback }}</div></td>
                                        {% else %}
                                            <td>{{ res.tracebackt }}</td>
                                        {% endif %}
                                    </tr>
                                {% endfor %}
                                {% else %}
                                    <p>No Item are available.</p>
                                {% endif %}
                            </tbody>
                  </table>
                    <div class="btn-group">
						 <button id="jobresultdel" class="btn btn-danger" style="display: none;" onclick="return checkSubmit()">删除结果</button>
                    </div>
                </div>
            </div>
        </form>

    </section>
        <!-- /.content -->
      </div>
{#接收子层回传参数#}
<input id="handle_status" value="" hidden="hidden">
<script>
function checkAll(sender, checkClass) {
    var checkItems = document.getElementsByTagName('input');
    for (var i = 0; i < checkItems.length; i++) {
        var checkItem = checkItems[i];
        if (checkItem.type === 'checkbox' && checkItem.className === 'item1') {
            checkItem.checked = sender.checked;
        }
    }
}
</script>
<script src="/static/plugins/datatables/jquery.dataTables.min.js"></script>
<script src="/static/plugins/datatables/dataTables.bootstrap.min.js"></script>
<script>
  $(function () {
{#    $("#example1").DataTable();#}
    $('#dataform').DataTable({
      "paging": true,
      "lengthChange": true,
      "searching": true,
      "ordering": true,
      "info": true,
      "autoWidth": true
    });
  });
</script>
<script>
function checkSubmit() {
    if (!confirm("确定删除？")) {
        window.event.returnValue = false;
    }
}
</script>
<script>
function tanchu(n){
  layer.open({
  type: 2,
  title: '信息修改',
  area: ['600px', '350px'],
  shadeClose: true, //点击遮罩关闭
  content: ['/setup/jobresultedit/' + n],
  end:function(){
        var handle_status = $("#handle_status").val();
        if ( handle_status == '1' ) {
            layer.msg('保存成功！',{
                icon: 1,
                time: 2000 //2秒关闭（如果不配置，默认是3秒）
            },function(){
                history.go(0);
            });
        } else if ( handle_status == '2' ) {
            layer.msg('修改失败！',{
                icon: 2,
                time: 2000 //2秒关闭（如果不配置，默认是3秒）
            },function(){
                history.go(0);
            });
        }
    }
  });
}
</script>
{% endblock %}
